package com.czollmann.android.activities;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;

import com.czollmann.android.Constants;
import com.czollmann.android.R;
import com.czollmann.android.StaticMethods;
import com.czollmann.android.utils.DataUtils;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;

public class StartupActivity extends BaseActivity {
	private final int SPLASH_DISPLAY_LENGHT = 1000;

	Facebook facebook = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.splash);
		
		final SharedPreferences settings = getSharedPreferences(
				Constants.SETTINGS_NAME, 0);
		if (settings.getBoolean(Constants.SETTINGS_USEFACEBOOK, false)) {
			// facebook = new Facebook(Constants.FACEBOOK_APP_ID);
			// facebook.authorize(this, new DialogListener() {
			// @Override
			// public void onComplete(Bundle values) {
			// }
			//
			// @Override
			// public void onFacebookError(FacebookError error) {
			// }
			//
			// @Override
			// public void onError(DialogError e) {
			// }
			//
			// @Override
			// public void onCancel() {
			// }
			// });
			// StaticMethods.setFacebook(facebook);
		}

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				final SharedPreferences settings = getSharedPreferences(
						Constants.SETTINGS_NAME, 0);
				DataUtils.initializeData(getContentResolver(), settings);
				Intent mainIntent = new Intent(StartupActivity.this,
						HomeActivity.class);
				StartupActivity.this.startActivity(mainIntent);
				StartupActivity.this.finish();
			}
		}, SPLASH_DISPLAY_LENGHT);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (facebook != null) {
			facebook.authorizeCallback(requestCode, resultCode, data);
		}
	}
}